package com.ruoyi.issues.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.issues.entity.Issues;
import com.ruoyi.issues.entity.query.IssueQuery;
import com.ruoyi.issues.mapper.IssuesMapper;
import com.ruoyi.issues.service.IssuesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 建议反馈表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-08-14
 */
@Service
public class IssuesServiceImpl extends ServiceImpl<IssuesMapper, Issues> implements IssuesService {

    @Override
    public Page<Issues> getList(String current, String limit, IssueQuery issueQuery) {

        Page<Issues> issuesPage = new Page<>();//创建page对象

        QueryWrapper<Issues> wrapper = new QueryWrapper<>();

        if (issueQuery != null){
            // 多条件组会 查询，条件可以为空
            String id = issueQuery.getId();
            String title = issueQuery.getTitle();
            String userid = issueQuery.getUserid();
            String giteeIssuesUrl = issueQuery.getGiteeIssuesUrl();
            Integer sort = issueQuery.getSort();
            Integer type = issueQuery.getType();
            Integer status = issueQuery.getStatus();
            String begin = issueQuery.getBegin();
            String end = issueQuery.getEnd();
            // 判断条件是否为空
            if (id != null) {
                wrapper.eq("id",id);
            }
            if (StringUtils.isNotEmpty(title)) {
                wrapper.like("title",title);
            }
            if (StringUtils.isNotEmpty(userid)){
                wrapper.eq("userid",userid);
            }
            if (StringUtils.isNotEmpty(giteeIssuesUrl)){
                wrapper.like("gitee_issues_url",giteeIssuesUrl);
            }
            if (sort != null){
                wrapper.eq("sort",sort);
            }
            if (type != null){
                wrapper.eq("type",type);
            }
            if (status != null){
                wrapper.eq("status",status);
            }
            if (StringUtils.isNotEmpty(begin)){
                wrapper.ge("bm_create",begin);
            }
            if (StringUtils.isNotEmpty(end)){
                wrapper.le("bm_create",end);
            }
        }

        wrapper.orderByDesc("sort","bm_modified"); // 添加默认排序
        baseMapper.selectPage(issuesPage, wrapper);
        return issuesPage;

    }
}
